package com.joycessh.service.impl;

import com.joycessh.dao.SeedListMapper;
import com.joycessh.domain.crawl.SeedList;
import com.joycessh.service.SeedListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Joycessh
 * @Description
 * @Date 5/9/19 4:17 PM
 */
@Slf4j
@Service
public class SeedListServiceImpl implements SeedListService {

    @Autowired
    private  SeedListMapper seedListMapper;

    @Override
    public boolean save(SeedList seedList) {
        return seedListMapper.insertSelective(seedList) == 1 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public boolean delete(Integer seedListId) {
        return seedListMapper.deleteByPrimaryKey(seedListId) == 1 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public boolean update(SeedList seedList) {
        return seedListMapper.updateByPrimaryKeySelective(seedList) == 1 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public List<SeedList> findAll() {
        List<SeedList> lists = new ArrayList<>(); // 类型推导
        try {
            lists = seedListMapper.selectAll();
        }catch (Exception e) {
            e.printStackTrace();
        }
        log.info(lists.toString());
        return lists;
    }

    @Override
    public SeedList getSeedList(Integer seedListId) {
        return seedListMapper.selectByPrimaryKey(seedListId);
    }
}
